#ifndef     __NOZZLE_MOTOR_H
#define     __NOZZLE_MOTOR_H

#include "../utils/object.h"
#include "../rtos/event_flags.h"
#include "../utils/error.h"
#include "../utils/step_motor_acc_ctrl.h"

namespace driver {

class NozzleMotor : public utils::StepMotorAccCtrl<NozzleMotor, 200, 3, 2000> {

public:
    static constexpr uint32_t FLAG_COMPLETE = 0x01;
    static constexpr uint32_t RESET_TIMEOUT = 30 * 1000;
    static constexpr uint32_t RESET_FREQ = 800;
    static constexpr uint32_t ADJ_MAX_COUNT = 3000;

    NozzleMotor();

    static bool is_alm();

    utils::Error run(uint32_t mm);

    static void disable_pwm();
    void notify();
    static void set_pwm_freq(uint32_t freq);
    static void enable_pwm(uint32_t freq);

private:
    utils::Error async_run(uint32_t position);
    utils::Error wait_for();

    void await();

    utils::Error reset();
    utils::Error reset_adj();

    bool m_reset_flag = false;
    uint32_t m_position = 0;
    rtos::EventFlags m_flags;
};

inline utils::Object<NozzleMotor> nozzleMotor;

}

#endif
